home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / GRAPHICS / IFRACS.ZIP / ZAP10.CPP < prev   
Encoding:
C/C++ Source or Header  |  1994-10-04  |  2.9 KB  |  120 lines

  1. /* ZAP10.CPP */
  2.      #include <graphics.h>
  3.      #include <bios.h>
  4.      #include <conio.h>
  5.      #include <stdio.h>
  6.      #include <stdlib.h>
  7.      #include <time.h>
  8.      #include  <math.h>
  9.      #include <complex.h>
  10. void main (void)
  11. {
  12.     char bd;
  13.      int k, ko, maxrow, maxcol, r, rr, r1, r2, r3, zee;
  14.      long numits, q;
  15.     complex a[5], b[5];
  16.      double qx, qy, qq, zx, zy, lx, ly, dx, dy, sx, sy, di;
  17.      double x, y;
  18.      complex z;
  19.      int driver = VGA;
  20.      int mode = 2;
  21.      initgraph( &driver, &mode, "c:\\tc\\bgi\\");
  22.      randomize();
  23.      di = 32767.;
  24.      numits = random(32700) + 100000;
  25. restart:
  26.       zee = random(3) + 2;
  27.       dx = 230.; dy = 180.; zx = 16.; zy = 12.;
  28.       rr = random(6) + 9;  /* color determination */
  29. golf:
  30.       r = random(6) + 9;
  31.       if (r == rr)
  32.       goto golf;
  33. foxtrot:
  34.       r1 = random(6) + 9;
  35.       if (r1 == r || r1 == rr)
  36.       goto foxtrot;
  37. hotel:
  38.       r2 = random(6) + 9;
  39.       if (r2 == r1 || r2 == r || r2 == rr)
  40.       goto hotel;
  41.       r3 = random(6) + 1;
  42. a[0] = complex(.65 - 1.3 * rand()/di, .65 - 1.3 * rand()/di);
  43. a[1] = complex(.65 - 1.3 * rand()/di, .65 - 1.3 * rand()/di);
  44. a[2] = complex(.65 - 1.3 * rand()/di, .65 - 1.3 * rand()/di);
  45. a[3] = complex(.65 - 1.3 * rand()/di, .65 - 1.3 * rand()/di);
  46. b[0] = complex(6.5 - 13. * rand()/di, 6.5 - 13. * rand()/di);
  47. b[1] = complex(6.5 - 13. * rand()/di, 6.5 - 13. * rand()/di);
  48. b[2] = complex(6.5 - 13. * rand()/di, 6.5 - 13. * rand()/di);
  49. b[3] = complex(6.5 - 13. * rand()/di, 6.5 - 13. * rand()/di);
  50. charlie:
  51.       cleardevice();
  52.       setcolor (1);
  53.       rectangle(1, 1, maxcol-1, 450);
  54.       moveto(1, 450);
  55.       settextstyle(SANS_SERIF_FONT, HORIZ_DIR,1);
  56.       setcolor (6);
  57.       x = 0.; y = 0.; z = complex(x, y);
  58. outtext("ESC to Quit      Space Bar for New Image      Press 'P' to Fill Window");
  59.  for (q = 1; q < numits; q++)
  60.    {
  61.      k = random(zee);
  62.      z = a[k] * z + b[k];  /* fractal equation */
  63.      x = real(z);
  64.      y = imag(z);
  65.      if (k == 0)    /* color correction*/
  66.      ko = r;
  67.      if (k == 1)
  68.      ko = rr;
  69.      if (k == 2)
  70.      ko = r1;
  71.      if (k == 3)
  72.      ko = r2;        /* end color correction */
  73.      if (k == 4)
  74.      ko = r3;
  75.       if (q > 10 )
  76.           {
  77.       putpixel (dx + zx * x, dy + zy * y, ko);
  78.  
  79.       if (x < sx)  /* sizing constants */
  80.       sx = x;
  81.       if (x > lx)
  82.       lx = x;
  83.       if (y < sy)
  84.       sy = y;
  85.       if (y > ly)
  86.       ly = y;
  87.            }
  88.       if (q == 10)    /* baseline for sizing */
  89.       {
  90.       sx = x;
  91.       lx = x;
  92.       sy = y;
  93.       ly = y;
  94.       }
  95.       if (kbhit() != 0)     /*  user break */
  96.      break;
  97.       if (abs(z)  >  800.)  /* "boundries' break */
  98.      break;
  99.    }
  100. skip:
  101.     bd = getch();
  102.     if (bd == 27)
  103.     goto finis;
  104.     if (bd == 32)
  105.     goto restart;
  106.     if (bd == 112)
  107.     {
  108.     zx = 610 / (lx - sx);
  109.     zy = 425 / (ly - sy);
  110.     dx = 320 - zx * (lx + sx) / 2;
  111.     dy = 225 - zy * (ly + sy) / 2;
  112.     goto charlie;
  113.     }
  114. finis:
  115.        if (bd != 27)
  116.        goto skip;
  117.       closegraph ();
  118. }
  119.  
  120.